<!DOCTYPE html>
<html lang="en" class="">
  
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
	<!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
	<title>购物车-我的购物车</title>
	<meta name="description" content="购物车，我的购物车">
	<meta name="Keywords" content="魅族手机官网商城、魅族官方在线商店、魅族在线商城、魅族官网在线商店、魅族商城、魅蓝商城">
	<link href="/static/home/img/favicon.ico" rel="shortcut icon" type="image/x-icon" />
	<link href="/static/home/img/favicon.ico" rel="icon" type="image/x-icon">
	<!-- Bootstrap -->
	<link href="/static/home/css/bootstrap.min.css" rel="stylesheet">
	<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
	<script src="/static/home/js/jquery-1.12.4.min.js"></script>
	<!-- Include all compiled plugins (below), or include individual files as needed -->
	<script src="/static/home/js/bootstrap.min.js"></script>

	<!-- 自定义 -->
	<link rel="stylesheet" type="text/css" href="/static/home/css/global.css">
	<link rel="stylesheet" type="text/css" href="/static/home/css/app.css">
	
	<link rel="stylesheet" type="text/css" href="/static/home/css/cart.css">
	<link rel="stylesheet" type="text/css" href="/static/home/css/cart-app.css">
	
	<script type="text/javascript" src="/static/home/js/rem.js"></script>
	<script type="text/javascript" src="/static/home/js/topNav.js"></script>
</head>
  
<body class="cart-app">
    <!-- 导航 -->
    <div class="layout-header" id="scroll-wrap">
		<nav class="navbar navbar-default header hidden-xs hidden-sm">
			<div class="container clearfix">
				<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
					<div class="layout-header-logo navbar-left">
						<a target="_blank" href="./index.html" class="layout-header-logo-link" alt="魅族科技">
							<img src="/static/home/img/logo.png">
						</a>
					</div>
					<div class="navbar-left">
						<ol class="breadcrumb">
							<li class="active">购物车</li>
							<li>确认订单</li>
							<li>在线支付</li>
							<li>完成 </li>
						</ol>
					</div>

					<!-- 人  购物车 -->
                    <ul class="nav navbar-nav navbar-right layout-header-service clearfix">
                        <li class="layout-header-service-item" id="layoutHeaderUser">
                            <!-- 判读是否会员登陆 -->
                            <a class="layout-header-service-link g-user" href="#">
                                <i class="glyphicon glyphicon-user"></i>
                                {{ request.session.VipUser.username|default:'<i class="glyphicon glyphicon-user" "></i>' }}
                            </a>
                            <!-- 会员头像隐藏下拉框 -->
                            <div class="layout-user-downmenu">
                                <ul class="layout-user-downmenu-list">
                                    <!-- 判断是否是会员  会员拥有退出登陆 -->
                                    {% if request.session.VipUser.uid %}
                                        <li class="layout-user-downmenu-item">
                                            <a href="{% url 'myhome_logout' %}" class="layout-user-downmenu-link">退出登录</a>
                                        </li>
                                        <li class="layout-user-downmenu-item">
                                            <a href="{% url 'myhome_myorder' %}" class="layout-user-downmenu-link" data-mtype="wmz_public_grzx_myorder">我的订单</a>
                                        </li>
                                    {% else %}
                                        <li class="layout-user-downmenu-item">
                                            <a href="{% url 'myhome_login' %}" class="layout-user-downmenu-link">立即登录</a>
                                        </li>
                                        <li class="layout-user-downmenu-item">
                                            <a href="{% url 'myhome_register' %}" target="_blank" class="layout-user-downmenu-link" data-mtype="wmz_public_grzx_register">立即注册</a>
                                        </li>
                                    {% endif %}
                                    
                                    <li class="layout-user-downmenu-item">
                                        <a href="#" class="layout-user-downmenu-link" data-mtype="wmz_public_grzx_mformy">M码通道</a>
                                    </li>
                                </ul>
                            </div>
                        </li>
                        <!-- 购物车 颜色随车内商品有无而变化 -->
                        <li class="layout-header-service-item layout-header-service-cart" id="layoutHeaderCart">
                            <a class="layout-header-service-link" href="{% url 'myhome_cartindex' %}" data-mtype="wmz_public_yt_cart">
                                {% block che %}
                                    <!-- 购物车有商品 购物车颜色改变 -->
                                    {% if request.session.len.changdu  %}
                                        <i style="color: red" class="glyphicon glyphicon-shopping-cart"></i>
                                    {% else %}
                                        <i class="glyphicon glyphicon-shopping-cart"></i>
                                    {% endif %}
                                    <!-- 购物车 车内商品数量 -->
                                    <span class="layout-header-service-cart-num gouwucheliang">            
                                        {{ request.session.len.changdu|default:0 }}
                                    </span>
                                {% endblock %}
                            </a>
                        </li>
                    </ul>
                    <!-- 头部二级标签 -->
                    <ul class="nav navbar-nav navbar-right layout-header-nav clearfix">
                        <li class="layout-header-nav-item">
                            <a href="/" class="layout-header-nav-link">魅族商城</a>
                            <p class="line-top hidden-xs"></p>
                        </li>
                        <!-- 导入 存放 自定义标签的.py文件 -->
                        {% load pagetag %}                  

                        {% erji %}
                                                                                                        
                        <li class="layout-header-nav-item">
                            <a href="#" class="layout-header-nav-link">社区</a>
                        </li>
                    </ul>

				</div>
			</div>
		</nav>
    </div>
    <!-- 导航 E-->
    <!-- 主内容区域 -->
    <div class="mainbody cart">
		<div class="container">
			<!-- 购物车详情头 -->
			<table class="cart-header">
				<tbody>
					<tr>
						<td class="cart-col-select col-md-3 col-xs-3 col-sm-3">
							<div class="cart-select-all JSelectAll">
								<div class="mz-checkbox"></div>
								<span class="cart-select-title">全选</span>
							</div>
						</td>
						<td class="cart-col-name col-md-3 hidden-xs hidden-sm">商品</td>
						<td class="cart-col-price col-md-2 hidden-xs hidden-sm">单价(元)</td>
						<td class="cart-col-number col-md-2 hidden-xs hidden-sm">数量</td>
						<td class="cart-col-total col-md-1 hidden-xs hidden-sm">小计(元)</td>
						<td class="cart-col-ctrl col-md-1 hidden-xs hidden-sm">操作</td>

					</tr>
				</tbody>
			</table>
			<!-- 购物车详情头 E-->
			
			<!-- 购物清单信息列表 -->
			<div class="cart-merchant-list">
				<div class="cart-merchant">
					<table class="cart-merchant-body">
						<tbody>							
							{% for i in request.session.buygoods.values %}
							<tr class="cart-product" id="pro5" gid="{{ i.id }}">
								<!-- 商品图片 -->
								<td class="cart-col-select col-md-3 col-xs-4 col-sm-4">  
									<div class="mz-checkbox "></div> 
									<a href="" class="cart-product-link" target="_blank">
										<img src="{{ i.pic }}" class="cart-product-img" alt="魅蓝 X">
									</a>
								</td>
								<!-- 商品名字 -->								
								<td class="cart-col-name col-md-3 col-xs-8 col-sm-8">
									<a href="meilanx.html" class="cart-product-link" target="_blank">
									  <p>{{ i.num }}</p>
									</a>
								</td>
								<!-- 商品单价 -->								
								<td class="cart-col-price col-md-2 hidden-xs hidden-sm">
									<p>
										<span class="cart-product-price jiage">{{ i.price }}</span>
									</p>
								</td>
								<!-- 商品数量 + - 按钮 -->								
								<td class="cart-col-number col-md-2 hidden-xs hidden-sm">
									<div class="cart-product-number-adder">
										<p class="cart-product-number-max show"></p>
										<div class="mz-adder">
											<button class="mz-adder-subtract disabled" edit="-" ></button>
											<div class="mz-adder-num">
												<input class="mz-adder-input" value="{{ i.num }}" type="text">
											</div>
											<button class="mz-adder-add" edit="+" ></button>
										</div>
									</div>
								</td>
								<!-- 商品小记 -->
								<td class="cart-col-total col-md-1 hidden-xs hidden-sm">
									<span class="cart-product-price total">
										{%  widthratio i.num 1 i.price  %}
									</span>
								</td>
								<!-- 商品删除 -->
								<td class="cart-col-ctrl col-md-1 hidden-xs hidden-sm">
									<div class="cart-product-remove">
										<a href="{% url 'myhome_cardelete' i.id %}">
											<span class="glyphicon glyphicon-remove"></span>
										</a>
									</div>
								</td>
							</tr>
							{% endfor %}
						</tbody>
					</table>
				</div>
			</div>
			<!-- 购物清单信息列表 E-->
		</div>
		<!-- 结算详情 -->
		<div class="cart-footer" id="cartFooter">
			<div class="container">
			   <div class="cart-footer-left col-md-6 col-xs-4 col-sm-4">
				   <div class="cart-select-all JSelectAll" data-mdesc="全选按钮" data-mtype="store_cart_all">		
					</div>
			    <span class="cart-footer-count">
			    	共
					<span class="cart-footer-num" id="totalCount"></span>
					件商品
			    </span>
				</div>
				<div class="cart-footer-right col-md-5 col-md-offset-1 col-sm-offset-2 col-xs-8 col-sm-6">
					<span class="cart-footer-sum">
						<span class="cart-footer-text">已优惠</span>
						<span class="cart-footer-num red" id="totalDiscount">0.00</span>
						<span class="cart-footer-text">元， 合计(不含运费)：</span>
						<span class="cart-footer-total" id="totalPrice">0</span>
					</span>
					<div class="mz-btn success" id="cartSubmit">去结算</div>
				</div>
			</div>
		</div><!-- 结算详情 E-->
	</div>
    <!-- 主内容区域 E-->
	
    <!-- 底部区域 -->
    <footer class="layout-footer  hidden-xs hidden-sm">
		<div class="container">
			<div class="layout-footer-top clearfix">
				<ul class="layout-footer-services clearfix">
					<li class="layout-footer-services-item">
					  <a href="#" class="layout-footer-services-link" target="_blank">
						<span class="layout-footer-service-wrap">
						  <i class="glyphicon glyphicon-sd-video"></i>
						</span>
						<span class="layout-footer-services-text">顺丰包邮</span></a>
					</li>
					<li class="layout-footer-services-item">
					  <a href="#" class="layout-footer-services-link" target="_blank">
						<span class="layout-footer-service-wrap">
						  <i class="glyphicon glyphicon-flash"></i>
						</span>
						<span class="layout-footer-services-text">100+ 城市次日送达</span></a>
					</li>
					<li class="layout-footer-services-item">
					  <a href="#" class="layout-footer-services-link" target="_blank">
						<span class="layout-footer-service-wrap">
						  <i class="glyphicon glyphicon-repeat"></i>
						</span>
						<span class="layout-footer-services-text">7 天无理由退货</span></a>
					</li>
					<li class="layout-footer-services-item">
					  <a href="#" class="layout-footer-services-link" target="_blank">
						<span class="layout-footer-service-wrap">
						  <i class="glyphicon glyphicon-refresh"></i>
						</span>
						<span class="layout-footer-services-text">15 天换货保障</span></a>
					</li>
					<li class="layout-footer-services-item">
					  <a href="#" class="layout-footer-services-link" target="_blank">
						<span class="layout-footer-service-wrap">
						  <i class="glyphicon glyphicon-wrench"></i>
						</span>
						<span class="layout-footer-services-text">1 年免费保修</span></a>
					</li>
					<li class="layout-footer-services-item">
					  <a href="#" class="layout-footer-services-link" target="_blank">
						<span class="layout-footer-service-wrap">
						  <i class="glyphicon glyphicon-map-marker"></i>
						</span>
						<span class="layout-footer-services-text">2300+ 线下体验店</span></a>
					</li>
					<li class="layout-footer-services-item">
					  <a href="#" class="layout-footer-services-link" target="_blank">
						<span class="layout-footer-service-wrap">
						  <i class="glyphicon glyphicon-sort"></i>
						</span>
						<span class="layout-footer-services-text">远程支持服务</span></a>
					</li>
					<li class="layout-footer-services-item">
					  <a href="#" class="layout-footer-services-link" target="_blank" data-mtype="wmz_public_foot_homerepair">
						<span class="layout-footer-service-wrap">
						  <i class="glyphicon glyphicon-home"></i>
						</span>
						<span class="layout-footer-services-text">上门快修</span></a>
					</li>
				</ul>
			  <div class="layout-footer-contact">
				<p class="layout-footer-contact-desc">24小时全国服务热线</p>
				<a href="tel:400-788-3333" class="layout-footer-contact-tel">400-788-3333</a>
				<p>
					<a href="javascript:void(0);" class="layout-footer-contact-online">
						<i class="layout-font layout-font-talk1"></i>
						<span class="text">在线客服</span>
					</a>
				</p>
			  </div>
			</div>
			<div class="layout-footer-bottom clearfix">
			<ul class="layout-footer-interlock clearfix">
				<li class="layout-footer-interlock-item">
					<a href="#" target="_blank" class="layout-footer-interlock-link">了解魅族</a></li>
				<li class="layout-footer-interlock-item">
					<a href="#" target="_blank" class="layout-footer-interlock-link">加入我们</a></li>
				<li class="layout-footer-interlock-item">
					<a href="#" target="_blank" class="layout-footer-interlock-link">联系我们</a></li>
				<li class="layout-footer-interlock-item">
					<a href="#" target="_blank" class="layout-footer-interlock-link">Flyme</a></li>
				<li class="layout-footer-interlock-item">
					<a href="#" target="_blank" class="layout-footer-interlock-link">魅族社区</a></li>
				<li class="layout-footer-interlock-item">
					<a href="#" target="_blank" class="layout-footer-interlock-link">天猫旗舰店</a></li>
				<li class="layout-footer-interlock-item">
					<a href="#" target="_blank" class="layout-footer-interlock-link">问题反馈</a></li>
				<li class="layout-footer-interlock-item">
					<a href="#" target="_blank" class="layout-footer-interlock-link">线上销售授权名单公示</a>
				 </li>
			</ul>
			<div class="layout-footer-copyright clearfix">
				<span class="layout-footer-copyright-left">
					<a class="layout-footer-copyright-link copyright-text">&copy;2017 Meizu Telecom Equipment Co., Ltd. All rights reserved.</a>
					<a class="layout-footer-copyright-link" hidefocus="true" href="#" target="_blank">粤ICP备13003602号-2</a>
					<a class="layout-footer-copyright-link" hidefocus="true" href="#" target="_blank">合字B2-20170010</a>
					<a class="layout-footer-copyright-link" hidefocus="true" href="#" target="_blank">营业执照</a>
					<a class="layout-footer-copyright-link" hidefocus="true" href="3" target="_blank">法律声明</a>
					<a class="layout-footer-copyright-link">粤公网安备 44049102496009 号</a>
					<a class="layout-footer-copyright-link" hidefocus="true" href="#" rel="nofollow" target="_blank">
						<i class="layout-icon layout-icon-license"></i>
					</a>
					<a class="layout-footer-copyright-link" hidefocus="true" href="#" rel="nofollow" target="_blank">
						<i class="layout-icon layout-icon-wel"></i>
					</a>
					<a class="layout-footer-copyright-link" hidefocus="true" href="#" rel="nofollow" target="_blank">
						<i class="layout-icon layout-icon-trust"></i>
					</a>
				</span>
				<ul class="layout-footer-media clearfix">
					<li class="layout-footer-media-item">
						<a href="http://weibo.com/meizumobile" class="layout-footer-media-link">
							<i class="layout-font layout-font-weibo"></i>
						</a>
					</li>
					<li class="layout-footer-media-item">
						<a href="javascript:void(0);" class="layout-footer-media-link wechat">
							<i class="layout-font layout-font-wechat"></i>
							<div class="layout-footer-media-wechat-qrcode">
								<img class="layout-footer-media-wechat-img" src="" alt="微信二维码">
							</div>
						</a>
					</li>
					<li class="layout-footer-media-item">
						<a href="#" class="layout-footer-media-link">
							<i class="layout-font layout-font-qzone"></i>
						</a>
					</li>
				</ul>
			</div>z
		</div>
    </footer>
    <!-- 底部区域 E -->
    <!-- 返回顶部 -->
    <div class="layout-magnet layout-magnet-show">
		<div class="layout-magnet-item layout-magnet-item-top">
			<a href="javascript:void(0);" class="layout-magnet-link" data-mtype="wmz_public_cbxf_top">
				<div class="layout-magnet-icon">
					<i class="glyphicon glyphicon-menu-up"></i>
				</div>
			</a>
		</div>
    </div>
    <!-- 返回顶部 E-->
	<script type="text/javascript">
        //回顶部
  		backTop();
  		//全选
  		allSelect();
  		//登录图片鼠标经过
        topLogin();


        // 商品数量 + - 按钮操作 修改商品数量 小计
  		$('.mz-adder-subtract,.mz-adder-add').click(function(){
  			// 先获取当前元素的数量
  			var num = Number($(this).parents('.mz-adder').find('input').val())
  			// 获取存放数量的 标签
			var beifen = $(this).parents('.mz-adder').find('input')
			// 获取 小计 标签
			var xiaoji = $(this).parents('tr').find('.total')

  			// 获取当前元素的edit属性
  			var edit = $(this).attr('edit')
  			// 获取点击商品的 商品id  名为gid
  			var gid = $(this).parents('tr').attr('gid')

  			$.get('{% url "myhome_cartedit" %}',{'num':num,'edit':edit,'gid':gid},function(data){
  				// data = {"jieguo":1,"liang":liang,"xiaoji":xiaoji}
  				if( data['jieguo'] == 1){
  					// 获取页面 数量 修改成 liang
  					liang =Number(data['liang'])  					
  					beifen.val(liang)  		
  					//  修改小计值
  					xiaoji.text(data['xiaoji'])
  					// 从新计算 被选中商品种和
  					totalnum()
  				}else{
  					console.log('修改失败')
  				}
  			},'json')
  		})


        // 点击去结算  满足两个要求   1:必须会员登录 2:必须有选中的商品
                    // 向后台提交的数据 选中商品id
        $('#cartSubmit').click(function(){

            // 判断有没有登录
            var VipUser = '{{ request.session.VipUser }}'
            // console.log(VipUser)
            if(!VipUser){
                alert('请登录')
                location.href = "/login/?nextpath="+{{ request.path }}+""
                return
            }
            // 判断是否选中商品
            ids = totalnum()
            if(ids.length == 0){
                alert('请选择购买商品')
                return 
            }
            location.href = "{% url 'myhome_orderconfirm' %}?ids="+ids

        })


  		// 方法  将每个被选中商品的 小计值 相加
  		// 		讲每个被选中商品的  数量  相加
  		function totalnum(){
  			totalprice = 0
  			allcount  = 0
            ids = []
  			$('.cart-merchant-body').find('.checked').each(function(){
  				// 合计金额
  				total = Number($(this).parents('tr').find('.total').text())  				
  				totalprice += total
  				// 合计数量
  				count = Number($(this).parents('tr').find('input').val())  				
  				allcount += count
                // 被选中的商品 的商品id
                gid = $(this).parents('tr').attr('gid')
                ids.push(gid)

  			})
  			// 修改结算数值
  			$('#totalPrice').text(totalprice)  			
  			// 修改页面选中商品数量
  			$('#totalCount').text(allcount)
            return ids
  		}	
	</script>
</body>

</html>